var ROUTER_INDEX = "index#";
var ROUTER_DEMO = "demo/";
var ROUTER_MAP_VIEW = ROUTER_DEMO + "pageMap";
var ROUTER_BOILER_VIEW = ROUTER_DEMO + "pageBoiler";
var ROUTER_CALCULATE_DATA_VIEW = ROUTER_DEMO + "pageCalculateData";
var ROUTER_MENU_VIEW = ROUTER_DEMO + "menu";

// http://localhost:8080/DAOTemplate/#demo/pageMap
window.AppRouter = Backbone.Router.extend({

    registerRoute : function(url, name) {
        this.route(url, name);
    },
    moveTo : function(route) {
        router.navigate(route, { trigger : true });
    },
    showView : function(selector, view, page) {
        console.log("AppBegin showView");
        if (this.currentView !== undefined) {
            this.currentView.close();
        }
        this.currentView = view;
        $(selector).html(this.currentView.render());
        InitView(page);
        console.log("AppEnd showView");
    },
    initialize : function() {
        this.method = "initialize";
        console.log("AppRouter start initialize");
//        this.registerRoute("", "menuViews");
        this.registerRoute("", "mailContentView");
        this.registerRoute(ROUTER_INDEX, "mapViews");
        this.registerRoute(ROUTER_MAP_VIEW, "mapViews");
        this.registerRoute(ROUTER_BOILER_VIEW, "boilerViews");
        this.registerRoute(ROUTER_CALCULATE_DATA_VIEW, "calculateDataViews");
//        this.registerRoute(ROUTER_MENU_VIEW, "menuViews");
        console.log("AppRouter end initialize");
    },
    mapViews : function (){
        RequireUtil.mapModule(function() {
            $.getJSON("./resources/assets/gps_location.js", function(map_location, status, xhr) {
                RequireUtil.mapTpl(function(tpl) {
                    router.showView(container,new ViewMap({
                        locationData : map_location,
                        tpl:tpl
                        }),PAGE_MAP_VIEW);
                });
            }).success(function() {
                console.log('success'); 
            }).error(function(data, status, xhr) { 
                console.log('error :' + status); 
                console.log(xhr); 
            });
            
           
        });
    },
    boilerViews : function (){
        RequireUtil.boilerModule(function() {
            RequireUtil.boilerTpl(function(tpl) {
                router.showView(container,new ViewBoiler({
                    tpl:tpl
                    }),PAGE_BOILER_VIEW);
            });
        });
    },
    
    calculateDataViews : function (){
        RequireUtil.calculateDataModule(function() {
            RequireUtil.calculateDataTpl(function(tpl) {
                router.showView(container,new ViewCalculateData({
                    tpl:tpl
                    }),PAGE_CALCULATE_DATA_VIEW);
            });
        });
    },
    
    menuViews : function(){
        RequireUtil.menuModule(function() {
                RequireUtil.menuTpl(function(tpl) {
                    router.showView(container,new ViewMenu({
                        tpl:tpl,
                        }),PAGE_MENU_VIEW);
                });
            });
    },
    
    mailContentView : function(){
        RequireUtil.mailModule(function() {
            RequireUtil.mailTpl(function(tpl) {
                router.showView(container,new ViewMail({
                    tpl:tpl,
                    }),PAGE_MAIL_VIEW);
            });
        });
    },
});
